package com.xiejun.bio;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class SocketServer {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9000);
        while (true) {
            //这个地方会有阻塞
            Socket socket = serverSocket.accept();
            handler(socket);
        }
    }

    private static void handler(Socket socket) throws IOException {
        byte[] bytes = new byte[1024];
        System.out.println("准备读取数据");
        int read = socket.getInputStream().read(bytes);
        System.out.println(read);
        System.out.println("读取完毕");
        if(read != -1){
            System.out.println("读取的数据为：" + new String(bytes, 0, read));
        }
    }
}
